﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using GeoRef;
using GeoRef.Exceptions;

namespace GeoRefUnitTest
{
    [TestFixture]
    public class GeoCodingTests
    {
        /// <summary>
        /// Performs some basic geocoding tests (without rising any exception).
        /// </summary>
        [Test]
        public void geocodingValidTests()
        {
            Console.WriteLine("Some valid geocoding tests...");

            // standard module interaction
            GeoQuery q = new GeoQuery();
            GeoLoc p = q.geoCoding("italy", "cagliari").First();
            Assert.IsNotNull(p);
            Console.WriteLine(p.Address + ": (" + p.ToString() + ")");

            p = q.geoCoding("via buonarroti, pisa, italy").First();
            Assert.IsNotNull(p);
            Console.WriteLine(p.Address + ": (" + p.ToString() + ")");

            p = q.geoCoding("italy", "firenze", "viale morgagni").First();
            Assert.IsNotNull(p);
            Console.WriteLine(p.Address + ": (" + p.ToString() + ")");

            p = q.geoCoding("italy", null, "56100", null).First();
            Assert.IsNotNull(p);
            Console.WriteLine(p.Address + ": (" + p.ToString() + ")");


            p = q.geoCoding("italy", null, "59100", "via bologna").First();
            Assert.IsNotNull(p);
            Console.WriteLine(p.Address + ": (" + p.ToString() + ")");
        }

        /// <summary>
        /// Performs some geocoding exceptions tests.
        /// </summary>
        [Test]
        public void geoCodingExceptionsTests()
        {
            // testing GeoCodingException
            GeoQuery q = new GeoQuery();
            GeoLoc p;
            bool error = false;
            try
            {
                p = q.geoCoding("myState").First();
            }
            catch (GeoCodingException gce)
            {
                Console.WriteLine(gce.ErrorMessage);
                error = true;
            }
            Assert.IsTrue(error);
        }
    }
}
